import request from '@/router/axios';
const scope = 'server'

export const loginByUsername = (username, password, code, randomStr) => request({
    url: '/auth/oauth/token',
    method: 'post',
    headers: { 'Authorization': 'Basic cGlnOnBpZw==' },
    meta: { isToken: false },
    params: {
        username,
        password,
        code,
        randomStr,
        grant_type: "password",
        scope: scope,
    },
    data: {
        username,
        password,
        code,
        randomStr,
        grant_type: "password",
        scope: scope,
    }
})

export const refeshToken = (refresh_token) => {
    const grant_type = 'refresh_token'
    return request({
        url: '/auth/oauth/token',
        method: 'post',
        headers: { 'Authorization': 'Basic cGlnOnBpZw==' },
        meta: { isToken: false },
        params: { refresh_token, grant_type, scope },
        data: { refresh_token, grant_type, scope }
    })
}

export const getUserInfo = () => request({
    url: '/admin/user/info',
    method: 'get'
});

export const getMenu = (parentId = -1) => request({
    url: '/admin/menu',
    method: 'get',
    params: {
        parentId
    }
});

export const getTopMenu = () => request({
    url: '/admin/menu/top',
    method: 'get'
});

export const sendLogs = (list) => request({
    url: '/user/logout',
    method: 'post',
    data: list
})

export const logout = () => request({
    url: '/auth/token/logout',
    meta: {
        isToken: false
    },
    method: 'delete'
})